package com.lanou3g.bookstore.util.listener_and_filter;

import com.lanou3g.bookstore.user.domain.AdminUser;
import com.lanou3g.bookstore.util.util.FatherFilter;

import javax.servlet.DispatcherType;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "AdminCategoryFilter", urlPatterns = "/adminjsps/admin/*",
        dispatcherTypes = {DispatcherType.REQUEST,
                DispatcherType.FORWARD, DispatcherType.INCLUDE})
public class AdminCategoryFilter extends FatherFilter {
    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        AdminUser user = (AdminUser) request.getSession().getAttribute("adminUser");
        if (user == null) {
            response.sendRedirect(request.getContextPath() + "/adminjsps/login.jsp");
        } else {
            chain.doFilter(request, response);
        }
    }
}
